unit uDMxh;

interface

uses
  SysUtils, Classes, DB, DBAccess, Uni, UniProvider, SQLServerUniProvider,
  MemDS, dxmdaset;

type
  Tdm = class(TDataModule)
    con1: TUniConnection;
    SQLServerUniProvider1: TSQLServerUniProvider;
    qrExcute: TUniQuery;
    qrSet: TdxMemData;
    qrSetDataBase: TStringField;
    qrSetDBName: TStringField;
    qrSetUsername: TStringField;
    qrSetPassword: TStringField;
    qrzfmxview: TUniQuery;
    procedure DataModuleDestroy(Sender: TObject);
    procedure DataModuleCreate(Sender: TObject);
  private
  public
    { Public declarations }
    conCount: Integer;
  end;

var
  dm: Tdm;

implementation

uses AES, ElAES;

{$R *.dfm}

procedure Tdm.DataModuleDestroy(Sender: TObject);
begin
  qrExcute.Close;
  con1.Close;
end;

procedure Tdm.DataModuleCreate(Sender: TObject);
begin
  if qrExcute.Active then
    qrExcute.Close;
  if FileExists('set.dat') then
  begin
    DecryptFile('set.dat', 'temp.dat', 'linlinghuang123');
    qrSet.LoadFromBinaryFile('temp.dat');
    DeleteFile('temp.dat');
  end;
  if not qrSet.Active then
    qrSet.Open;
  conCount := qrSet.RecordCount;
  if conCount = 0 then
    Exit;

  if conCount = 1 then
  qrSet.First;
  if con1.Connected then
    con1.Close;
  con1.Server := qrSetDataBase.AsString;
  con1.Database := qrSetDBName.AsString;
  con1.Username := qrSetUsername.AsString;
  con1.Password := qrSetPassword.AsString;
  con1.Connect;
  
  qrSet.Close;
end;

end.
